define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'member_appeal/index' + location.search,
                    // add_url: 'member_appeal/add',
                    // edit_url: 'member_appeal/edit',
                    del_url: 'member_appeal/del',
                    // multi_url: 'member_appeal/multi',
                    // import_url: 'member_appeal/import',
                    table: 'member_appeal',
                }
            });

            var table = $("#table");

            table.on('post-common-search.bs.table', function (event, table) {
                var form = $("form", table.$commonsearch);
                $("input[name='uid']", form)
                    .addClass("selectpage")
                    .data("source", "user/user/selectpage")
                    .data("primaryKey", "id")
                    .data("field", "nickname")
                    .data("orderBy", "id desc");
                $("input[name='mid']", form)
                    .addClass("selectpage")
                    .data("source", "wdsxh/Member/selectpage")
                    .data("primaryKey", "id")
                    .data("field", "name")
                    .data("orderBy", "id desc");
                Form.events.cxselect(form);
                Form.events.selectpage(form);
            });

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                search: false,
                commonSearch: true,
                searchFormVisible: false,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'), operate: false, sortable: true},
                        {field: 'uid', title: __('Uid'), visible: false},
                        {field: 'user.nickname', title: __('Uid'), operate: false},
                        {field: 'mid', title: __('Mid'), visible: false},
                        {field: 'member.name', title: __('Mid'), operate: false},
                        {field: 'name', title: __('Name'), operate: 'LIKE'},
                        {field: 'mobile', title: __('Mobile'), operate: 'LIKE'},
                        // {field: 'content', title: __('Content'), operate: false},
                        // {field: 'images', title: __('Images'), operate: false, formatter: Table.api.formatter.images},
                        {field: 'is_open', title: __('Is_open'), searchList: {"0":__('Is_open 0'),"1":__('Is_open 1')}, formatter: Table.api.formatter.status},
                        {field: 'reply_time', title: __('Reply_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime, sortable: true},
                        {field: 'status', title: __('Status'), searchList: {"0":__('Status 0'),"1":__('Status 1')}, formatter: Table.api.formatter.status},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime, sortable: true},
                        {
                            field: 'operate',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            buttons: [
                                {
                                    name: 'detail',
                                    text: '详情',
                                    title: '详情',
                                    classname: 'btn btn-xs btn-primary btn-dialog',
                                    icon: 'fa fa-list',
                                    url: function (res) {
                                        return 'member_appeal/detail/ids/' + res.id;
                                    },
                                    callback: function (data) {
                                        Layer.alert("接收到回传数据：" + JSON.stringify(data), {title: "回传数据"});
                                    },
                                    visible: function (row) {
                                        return true;
                                    }
                                },{
                                    name: 'agree',
                                    text: '处理',
                                    title: '处理',
                                    classname: 'btn btn-xs btn btn-success btn-view btn-dialog',
                                    icon: 'fa fa-check',
                                    url: function (res) {
                                        return 'member_appeal/agree/ids/' + res.id;
                                    },
                                    callback: function (data) {
                                        Layer.alert("接收到回传数据：" + JSON.stringify(data), {title: "回传数据"});
                                    },
                                    visible: function (row) {
                                        if(row.status == 0){
                                            return true;
                                        }
                                    },
                                    refresh:true
                                },
                            ],
                            formatter: Table.api.formatter.operate
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        agree: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
